#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int n = nums.size();
        int ret = -1;
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (count == 0) {
                count = 1;
                ret = nums[i];
            }
            else {
                if (nums[i] == ret) count++;
                else count--;
            }
        }
        count = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] == ret) count++;
        }
        return count * 2 > n ? ret : -1;
    }
};

class Solution {
public:
    int findClosest(vector<string>& words, string word1, string word2) {
        int p1 = -1, p2 = -1, ret = INT_MAX;
        for (int i = 0; i < words.size(); i++) {
            if (words[i] == word1) p1 = i;
            else if (words[i] == word2) p2 = i;
            if (p1 != -1 && p2 != -1) ret = min(ret, abs(p1 - p2));
        }
        return ret;
    }
};